package com.CuandoLlegaAndroid;

import com.CuandoLlegaAndroid.R;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;

public class SplashScreen extends Activity {

	private Thread mSplashThread;    

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Splash screen view
		setContentView(R.layout.splash);

		final SplashScreen sPlashScreen = this;   

		
		 // Load the ImageView that will host the animation and
		 // set its background to our AnimationDrawable XML resource.
//		 final ImageView img = (ImageView)findViewById(R.id.SplashImageView);
//
//		 img.setBackgroundResource(R.drawable.clock);
//
//		 img.post(new Runnable() {
//		    @Override
//		    public void run() {
//		        AnimationDrawable frameAnimation =
//		            (AnimationDrawable) img.getBackground();
//		        frameAnimation.start();
//		    }
//		});
		
		// The thread to wait for splash screen events
		mSplashThread =  new Thread(){
			@Override
			public void run(){
				try {
					synchronized(this){
						// Wait given period of time or exit on touch
						wait(3500);
					}
				}
				catch(InterruptedException ex){                    
				}

				finish();

				// Run next activity
				Intent intent = new Intent();
				intent.setClass(sPlashScreen, Main.class);
				startActivity(intent);
				stop();                    
			}
		};

		mSplashThread.start();
	}

	/**
	 * Processes splash screen touch events
	 */
	@Override
	public boolean onTouchEvent(MotionEvent evt)
	{
		if(evt.getAction() == MotionEvent.ACTION_DOWN)
		{
			synchronized(mSplashThread){
				mSplashThread.notifyAll();
			}
		}
		return true;
	}   
} 